﻿using System;

namespace _03_MemoModel
{
    class Program
    {
        static void Main(string[] args)
        {
            // 大战Boss前
            GameRole lixiaoyao = new GameRole();
            lixiaoyao.GetInitState();
            lixiaoyao.StateDisplay();

            // 保存进度
            RoleStateCaretaker roleStateCaretaker = new RoleStateCaretaker();
            roleStateCaretaker.memento = lixiaoyao.SaveState();

            // 大战Boss时，损耗严重
            lixiaoyao.Fight();
            lixiaoyao.StateDisplay();

            // 恢复之前状态
            lixiaoyao.RecoveryState(roleStateCaretaker.memento);
            lixiaoyao.StateDisplay();


            Console.Read();
        }
    }

    // 游戏角色
    class GameRole
    {
        // 生命力
        public int Vitality { get; set; }
        // 攻击力
        public int Attack { get; set; }
        // 防御力
        public int Defense { get; set; }
        // 状态显示
        public void StateDisplay()
        {
            Console.WriteLine("角色当前状态：");
            Console.WriteLine($"体力：{this.Vitality}");
            Console.WriteLine($"攻击力：{this.Attack}");
            Console.WriteLine($"防御力：{this.Defense}");
            Console.WriteLine("");
        }
        // 获得初始状态
        public void GetInitState()
        {
            this.Vitality = 100;
            this.Attack = 100;
            this.Defense = 100;
        }
        // 战斗
        public void Fight()
        {
            // 战斗后的损耗
            this.Vitality = 0;
            this.Attack = 0;
            this.Defense = 0;
        }
        // 保存角色状态
        public RoleStateMemento SaveState()
        {
            return new RoleStateMemento(Vitality, Attack, Defense);
        }
        // 恢复角色状态
        public void RecoveryState(RoleStateMemento memeto)
        {
            this.Vitality = memeto.Vitality;
            this.Attack = memeto.Attack;
            this.Defense = memeto.Defense;
        }
    }

    // 角色状态存储箱类
    class RoleStateMemento
    {
        public RoleStateMemento(int vit, int atk, int def)
        {
            this.Vitality = vit;
            this.Attack = atk;
            this.Defense = def;
        }

        //生命力
        public int Vitality { get; set; }
     

        //攻击力
        public int Attack { get; set; }


        //防御力
        public int Defense { get; set; }

    }

    // 角色状态管理类
    class RoleStateCaretaker
    {
       public RoleStateMemento memento { get; set; }
    }
}